package Reseau;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ReceiveTCP extends Thread{
    Socket clientSocket;
    File file;
    int port = 2234;
    
    public ReceiveTCP(InetAddress adresse){
        
        PrintWriter out = null;
        try {
            Socket socket = new Socket(adresse, 2234);
            
            System.out.println("test05");
            clientSocket = socket;
            out = new PrintWriter( clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(
               new InputStreamReader(
                      clientSocket.getInputStream()));
            
            System.out.println("test06");
            
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String request;
            String reply;
            System.out.println("test07");
            while (true) {
                 request = stdIn.readLine(); // l'utilisateur entre la requête
                 out.println(request);      // envoyer la requête au serveur
                 reply = in.readLine();    // attendre la réponse
                System.out.println(reply); // imprimer la réponse
            }
            

            
        } catch (IOException ex) {
            Logger.getLogger(ReceiveTCP.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            System.out.println("test09");
            out.close();
        }
        
        
        
    }   
}
